//
//  STProductGoodsListView.m
//  CuiBoStore
//
//  Created by 崔博 on 16/12/12.
//  Copyright © 2016年 崔博. All rights reserved.
//

#import "STProductGoodsListView.h"
#import "STGoodsListCell.h"
#import "STProductGoodsModel.h"
@interface STProductGoodsListView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation STProductGoodsListView
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    if (self == [super initWithFrame:frame collectionViewLayout:layout]) {
        self.delegate = self;
        self.dataSource = self;
        [self registerNib:[UINib nibWithNibName:@"STGoodsListCell" bundle:nil] forCellWithReuseIdentifier:@"STGoodsListCell"];
    }
    return self;
}
#pragma mark - delegate
#pragma mark - collectionDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"STGoodsListCell";
    STGoodsListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    cell.goodsModel = self.dataList[indexPath.row];
    return cell;
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    STProductGoodsModel *m = self.dataList[indexPath.row];
    if (self.block) {
        self.block(m.GoodsId);
    }
}

#pragma mark - set
- (void)setDataList:(NSArray *)dataList
{
    _dataList = dataList;
    [self reloadData];
}
@end
